<template>
	<view class="my-order">
		<Line />
		<view class="order-header">
			<view class="header-item" v-for="(item,index) of tabList" :key="index"
				:class="{'active':index === tabIndex}" @tap="changeIndex(index)">{{item.name}}</view>
		</view>
		<block v-for="(tabitem,tabl) in tabList" :key="tabl">
			<view v-show="tabl==tabIndex" class="order-main-content">
				<view class="order-main" v-if="tabitem.list.length">
					<!-- 商品 -->
					<view class="order-main-container" v-for="(k,i) in tabitem.list" :key="i">
						<view class="order-goods">
							<view class="goods-status f-active-color"  v-if="tabList[0].list[0].goods_item.length">{{k.status}}</view>
							<view class="goods-content" v-for="(item,index) in k.goods_item" :key="index">
								<image class="goods-img" :src="item.imgUrl" mode=""></image>
								<view class="goods-text">
									<view class="goods-name">{{item.name}}</view>
									<view class="goods-size f-color">{{item.attrs}}</view>
									<view class="f-active-color goods-size">
										7天无理由
									</view>
								</view>
								<view>
									<view>¥{{item.pprice}}</view>
									<view class="f-color">*{{item.num}}</view>
								</view>
							</view>
						</view>
						<view v-if="tabList[0].list[0].goods_item.length">
							<Line />
							<!-- 总价 -->
							<view class="total-price">
								订单金额: <text class="f-active-color">¥{{totalPrice}}</text> (包含运费¥0.00)
							</view>
							<Line />
							<!-- 支付 -->
							<view class="payment">
								<view class="payment-text f-active-color" @tap="goPayment">支付</view>
							</view>
						</view>
						<view class="no-order" v-else>
							<view class="no-order-text">您还没有相关订单</view>
							<view class="no-order-home" @tap="goIndex">去首页逛逛</view>
						</view>
					</view>
				</view>
				<view class="no-order" v-else>
					<view class="no-order-text">您还没有相关订单</view>
					<view class="no-order-home" @tap="goIndex">去首页逛逛</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import Line from "@/components/Line/Line.vue"
	export default {
		data() {
			return {
				tabList: [
					{
						name: "全部",
						list: [{
							status: "待付款",
							totalPrice: this.$store.getters.totalPrice,
							goods_item: this.$store.getters.list,
						}]
					},
					{
						name: "待付款",
						list: []
					},
					{
						name: "待发货",
						list: []
					},
					{
						name: "待收货",
						list: []
					},
					{
						name: "待评价",
						list: []
					}
				],
				tabIndex: 0
			};
		},
		methods: {
			changeIndex(index) {
				this.tabIndex = index
			},
			goPayment(){
				uni.navigateTo({
					url:"/pages/payment/payment"
				})
			},
			goIndex(){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}
		},
		computed:{
			totalPrice(){
				let price = 0
				this.$store.state.cart.list.forEach(v => {
					let price_ = v.price ? v.price : v.pprice
					price += Number(price_);
				})
				return price
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-order {
		display: flex;
		flex-direction: column;
		background-color: #F7F7F7;
		height: calc(100vh - 44px);
		/* #ifdef APP-PLUS */
		height: 100vh;

		/* #endif */
		.order-header {
			display: flex;
			align-items: center;
			background-color: #fff;
			border-bottom: 2rpx solid #F7F7F7;

			.header-item {
				line-height: 120rpx;
				flex: 1;
				text-align: center;
			}

			.active {
				border-bottom: 4rpx solid #49BDFB;
			}
		}

		.order-main-content {
			flex: 1;

			.order-main {
				height: 100%;
				.order-main-container{
					height: 100%;
					//商品
					.order-goods {
						.goods-status {
							display: flex;
							align-items: center;
							justify-content: flex-end;
							background-color: #fff;
							padding: 20rpx;
						}
					
						.goods-content {
							display: flex;
							justify-content: space-between;
							align-items: center;
							background-color: #f7f7f7;
							padding: 20rpx;
					
							.goods-img {
								width: 160rpx;
								height: 160rpx;
							}
					
							.goods-text {
								display: flex;
								flex-direction: column;
								justify-content: space-around;
								width: 360rpx;
								height: 160rpx;
								padding: 0 10rpx;
					
								.goods-name {
									display: -webkit-box;
									-webkit-line-clamp: 2;
									-webkit-box-orient: vertical;
									overflow: hidden;
									text-overflow: ellipsis;
									font-size: 26rpx;
									height: 68rpx;
								}
					
								.goods-size {
									font-size: 24rpx;
								}
							}
						}
					}
					
					//总价
					.total-price {
						display: flex;
						justify-content: flex-end;
						align-items: baseline;
						background-color: #fff;
						padding: 20rpx;
					}
					
					//支付
					.payment {
						display: flex;
						justify-content: flex-end;
						background-color: #fff;
						padding: 20rpx;
					
						.payment-text {
							border: 2rpx solid #49BDFB;
							padding: 6rpx 40rpx;
							border-radius: 30rpx;
						}
					}
				}
			}
		}


		//没有数据的样式
		.no-order {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			background-color: #fff;
			height: 100%;

			.no-order-text {
				margin-bottom: 10rpx;
			}

			.no-order-home {
				padding: 10rpx 70rpx;
				border: 1rpx solid #49BDFB;
				color: #49BDFB;
				border-radius: 40rpx;
				margin-top: 10rpx;
			}
		}
	}
</style>
